﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;

namespace ComputerArchitecture.Core.Logging
{
    public class NLogFacadeLoggingService : ILoggingService
    {
        #region Fields

        private readonly Logger _logger;

        #endregion

        #region Constructors

        public NLogFacadeLoggingService(Logger logger)
        {
            if (ReferenceEquals(logger, null))
            {
                throw new ArgumentNullException("logger");
            }
            _logger = logger;
        }

        public NLogFacadeLoggingService()
            : this(LogManager.GetCurrentClassLogger())
        {
        }

        public NLogFacadeLoggingService(string name)
            : this(LogManager.GetLogger(name))
        {
        }

        #endregion

        #region Methods

        public void LogInfo(string message)
        {
            _logger.Info(message);
        }

        public void LogError(string message)
        {
            _logger.Error(message);
        }

        public void LogWarning(string message)
        {
            _logger.Warn(message);
        }

        public void LogWarning(string format, params object[] args)
        {
            _logger.Warn(format, args);
        }

        public void EnableLogging()
        {
            if (!LogManager.IsLoggingEnabled())
            {
                LogManager.EnableLogging();
            }
        }

        public void DisableLogging()
        {
            if (LogManager.IsLoggingEnabled())
            {
                LogManager.DisableLogging();
            }
        }

        public void LogInfo(string format, params object[] args)
        {
            _logger.Info(format, args);
        }

        public void LogError(string format, params object[] args)
        {
            _logger.Error(format, args);
        }

        #endregion
    }
}
